CREATE PROCEDURE [dbo].[ps_afflivres] @deb INT, @ligpage INT
AS
BEGIN
SET NOCOUNT ON
SELECT LIV_ID, LIV_ISBN, LIV_TITRE, LIV_SOUSTITRE, LIV_PRIXHT, LIV_RESUME, LIV_DATEPUBLICATION, LIV_NBPAGES, LIV_STOCK, TVA_TAUX, EDI_NOM, GEN_LABEL, EVE_LABEL
FROM (
SELECT LIV_ID, LIV_ISBN, LIV_TITRE, LIV_SOUSTITRE, LIV_PRIXHT, LIV_RESUME, LIV_DATEPUBLICATION, LIV_NBPAGES, LIV_STOCK, TVA_TAUX, EDI_NOM, GEN_LABEL, EVE_LABEL, row_number() OVER (ORDER BY LIV_ID) AS rownum
FROM T_LIVRES L INNER JOIN T_TVA T
ON L.TVA_ID = T.TVA_ID
INNER JOIN T_EDITEURS E
ON L.EDI_ID = E.EDI_ID
INNER JOIN T_GENRES G
ON L.GEN_ID = G.GEN_ID
LEFT OUTER JOIN T_EVENTS EV
ON L.EVE_ID = EV.EVE_ID) AS A
WHERE A.rownum BETWEEN (@deb+1) AND (@deb + @ligpage)
END

GO

/*
DECLARE @deb INT;
DECLARE @ligpage INT;
SET @deb = 5;
SET @ligpage =5;


SELECT LIV_ID, LIV_ISBN, LIV_TITRE, LIV_SOUSTITRE, LIV_PRIXHT, LIV_RESUME, LIV_DATEPUBLICATION, LIV_NBPAGES, LIV_STOCK, TVA_TAUX, EDI_NOM, GEN_LABEL, EVE_LABEL
FROM (
SELECT LIV_ID, LIV_ISBN, LIV_TITRE, LIV_SOUSTITRE, LIV_PRIXHT, LIV_RESUME, LIV_DATEPUBLICATION, LIV_NBPAGES, LIV_STOCK, TVA_TAUX, EDI_NOM, GEN_LABEL, EVE_LABEL, row_number() OVER (ORDER BY LIV_ID) AS rownum
FROM T_LIVRES L INNER JOIN T_TVA T
ON L.TVA_ID = T.TVA_ID
INNER JOIN T_EDITEURS E
ON L.EDI_ID = E.EDI_ID
INNER JOIN T_GENRES G
ON L.GEN_ID = G.GEN_ID
LEFT OUTER JOIN T_EVENTS EV
ON L.EVE_ID = EV.EVE_ID) AS A
WHERE A.rownum BETWEEN (@deb+1) AND (@deb + @ligpage)
*/


